package com.ruoyi.quartz.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.quartz.domain.BaseArticle;
import com.ruoyi.quartz.service.IBaseArticleService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/base/article")
public class BaseArticleController extends BaseController {

    @Resource
    private IBaseArticleService iBaseArticleService;

    @GetMapping("/list")
    public TableDataInfo list(BaseArticle baseArticle)
    {
        startPage();
        List<BaseArticle> list = iBaseArticleService.selectAll(baseArticle);
        return getDataTable(list);
    }

    @GetMapping(value = "/{art_id}")
    public AjaxResult getInfo(@PathVariable("art_id") Integer art_id)
    {
        return AjaxResult.success(iBaseArticleService.selectArticleById(art_id));
    }

    @PostMapping
    public AjaxResult add(@Validated @RequestBody BaseArticle baseArticle)
    {
        baseArticle.setCreateBy(getUsername());
        return toAjax(iBaseArticleService.insertArticle(baseArticle));
    }


    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BaseArticle baseArticle)
    {
        baseArticle.setUpdateBy(getUsername());
        return toAjax(iBaseArticleService.updateArticle(baseArticle));
    }

    @DeleteMapping("/{art_ids}")
    public AjaxResult remove(@PathVariable Integer[] art_ids)
    {
        return toAjax(iBaseArticleService.deleteArticleByIds(art_ids));
    }

}
